﻿@typeparam TItem
@inherits _BaseDataGridRowEdit<TItem>
@if ( EditMode == DataGridEditMode.Form )
{
    <TableRowCell ColumnSpan="@(Columns.Count() + 1)">
        <Row>
            @foreach ( var column in Columns )
            {
                @if ( column.ColumnType == DataGridColumnType.Command )
                    continue;

                @if ( CellAreEditable( column ) )
                {
                    <Column ColumnSize="ColumnSize.IsHalf.OnDesktop" Padding="Blazorise.Padding.Is2.OnX.Is2.OnY">
                        <Field>
                            <FieldLabel>
                                @column.Caption
                            </FieldLabel>
                            <FieldBody>
                                <_DataGridCell TItem="TItem" Column="@column" Item="@Item" CellEditContext="@CellValues[column.ElementId]" />
                            </FieldBody>
                        </Field>
                    </Column>
                }
            }
        </Row>
        <Row>
            <Column>
                @if ( ParentDataGrid?.CommandColumn?.SaveCommandTemplate != null )
                {
                    @ParentDataGrid.CommandColumn.SaveCommandTemplate( new CommandContext<TItem>
                    {
                        Clicked = Save,
                        Item = Item,
                    } );
                }
                else
                {
                    <Button Color="Color.Link" Clicked="@Save">Save</Button>
                }
                @if ( ParentDataGrid?.CommandColumn?.CancelCommandTemplate != null )
                {
                    @ParentDataGrid.CommandColumn.CancelCommandTemplate( new CommandContext<TItem>
                    {
                        Clicked = Cancel,
                        Item = Item,
                    } );
                }
                else
                {
                    <Button Color="Color.Link" Clicked="@Cancel">Cancel</Button>
                }
            </Column>
        </Row>
    </TableRowCell>
}
else if ( EditMode == DataGridEditMode.Inline )
{
    @foreach ( var column in Columns )
    {
        @if ( column.ColumnType == DataGridColumnType.Command )
        {
            @if ( ParentDataGrid?.Editable == true )
            {
                <_DataGridRowCommand TItem="TItem" Item="@Item" EditState="DataGridEditState.Edit" Save="@Save" Cancel="@Cancel" Width="@column.Width" />
            }
        }
        else
        {
            <TableRowCell width="@column.Width">
                @if ( ParentDataGrid?.Editable == true && CellAreEditable( column ) )
                {
                    <_DataGridCell TItem="TItem" Column="@column" Item="@Item" CellEditContext="@CellValues[column.ElementId]" />
                }
                else
                {
                    if ( column.DisplayTemplate != null )
                    {
                        @column.DisplayTemplate( Item )
                    }
                    else
                    {
                        @column.GetValue( Item )
                    }
                }
            </TableRowCell>
        }
    }
}